
import requests
def textvalue(message):
        
    url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=el9EGO8H573CvnUOVvWMpqgs&client_secret=9mT2xWGT3uOydbv8ZPBLU3MfAbdIqm4L"
    
    payload = ""
    headers = {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
    
    response = requests.request("POST", url, headers=headers, data=payload)
    token=response.json()['access_token']
    url='https://aip.baidubce.com/rpc/2.0/nlp/v1/sentiment_classify?access_token='+token
    response=requests.post(url,json={"text":message})
    json_data=response.json()
    negative = json_data['items'][0]['negative_prob'] 
    positive = (json_data['items'][0]['positive_prob']) 
   
    if (positive > negative):  
        return 2
    elif (positive == negative):  
        return 1
    else:
        return 0 
